package org.grow.wind.filter;


import org.springframework.stereotype.Component;
import org.springframework.web.filter.OncePerRequestFilter;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author: xwg
 * @CreateDate: 2025/9/1
 */

@Component
public class PicCountFilter extends OncePerRequestFilter {

    private Integer count = 0;
    @Override
    protected void doFilterInternal(HttpServletRequest request,
                                    HttpServletResponse response,
                                    FilterChain filterChain) throws ServletException, IOException {
//        /statics/tess05.png
        if(request.getRequestURI().contains("/statics")){

            System.out.println("该请求正在访问静态资源 " + request.getRequestURI());
            if(request.getRequestURI().contains("/tess05.png")){
                count++;
                System.out.println("目前tess05.png被访问了次数是："+count);
            }
        }
//        放行
        filterChain.doFilter(request,response);

    }
}
